<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工程其他合同列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>合同编号：</label>
                                <input type="text" name="orderNo" autoComplete="off"/>
                            </li>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" name="name" autoComplete="off"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                 <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="gcgl:other:edit"> -->
<!--                     <i class="fa fa-edit"></i> 修改 -->
<!--                 </a> -->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="gcgl:other:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:other:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success single disabled" onclick="addzsht()" shiro:hasPermission="gcgl:other:edit">
                    <i class="fa fa-plus"></i> 上传正式合同
                </a>
                <a class="btn btn-success single disabled" onclick="addfp()" shiro:hasPermission="gcgl:other:fp">
                    <i class="fa fa-plus"></i> 上传发票
                </a>
                <a class="btn btn-success single disabled" onclick="addfk()" shiro:hasPermission="gcgl:other:fp">
                    <i class="fa fa-plus"></i> 去付款
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('gcgl:other:edit')}]];
        var removeFlag = [[${@permission.hasPermi('gcgl:other:remove')}]];
        var types = [[${@dict.getType('gcgl_other_type')}]];
        var datas = [[${@dict.getType('gcgl_cbpg_status')}]];
        var prefix = ctx + "gcgl/other";

        $(function() {
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "工程其他合同",
                sortName: "id desc",
                sortOrder: "",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'gcProjectid',
                    title: '合同ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '合同编号'
                },
                {
                    field: 'type',
                    title: '合同类型',
                    formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(types, item.type);
		            }
                },
                {
                    field: 'name',
                    title: '项目名称'
                },
                {
                    field: 'zongje',
                    title: '合同总金额'
                },
                {
                    field: 'supplyName',
                    title: '供应商名称'
                },
                {
                    field: 'descs',
                    title: '合同简要说明'
                },
                {
                    field: 'createUser',
                    title: '创建人'
                },
                {
                    field: 'createAt',
                    title: '创建时间'
                },
                {
                    field: 'spr',
                    title: '工程经理审批'
                },
		        {
                    field: 'zjl',
                    title: '总经理审批'
                },
                {
		            field: 'status',
		            title: '状态',
		            align: "left",
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datas, item.status);
		            }
		        },
		        {
                    field: 'spyj',
                    title: '审批意见',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status<3){
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editHome(\'' + row.gcProjectid + '\')"><i class="fa fa-plus"></i>上传项目资料</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-plus"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
      	//上传正式合同
	    function addzsht(){
	    	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("请务选择多条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            
            if(status==3 || status==6){
            	$.modal.openTab('工程其它正式合同',"/gcgl/other/editZsht/"+rows.join());
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
	    }
        
        function addfk(){
	  		table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("请务选择多条记录");
                return;
            }
            
			var status = $.table.selectColumns("status");
            
            if(status==6){
            	$.modal.openTab('工程项目支付',"/gcgl/fk/addother/"+rows.join()+"/3");
            }else{
            	$.modal.alertWarning("该记录未上传正式合同或审核通过！");
                return;
            }
	  	}
        
        function editHome(projectId) {
            $.modal.openTab('打开',"/gcgl/project/editHome/"+projectId);
        }
        
        function detail(projectId) {
            $.modal.openTab('打开',"/gcgl/other/detail/"+projectId);
        }
        
        function addfp(){
	  		table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("请务选择多条记录");
                return;
            }
            
			var status = $.table.selectColumns("status");
            
            if(status==6){
            	$.modal.open('工程其他合同发票',"/gcgl/fkfp/add/"+rows.join()+"/3");
            }else{
            	$.modal.alertWarning("该记录未上传正式合同或审核通过！");
                return;
            }
	  	}
    </script>
</body>
</html>